<?php
	if ($_POST['wyb_pac_ed']) {
	foreach ($_POST['wyb_pac_ed'] as $i => $w){
		$_SESSION['wyb_pac_ed_id']=$i;
	}
}
	if ($_SESSION['config']=='admin') {
	if ($_SESSION['lacz_pac_ktory']=='0'){
	$sql="select * from pac where id =".$_SESSION['pac_zr'][0];
	$_SESSION['pac_zr'][1]=$_SESSION['pac_zr'][0];
	}
	elseif ($_SESSION['lacz_pac_ktory']=='1'){
	$sql="select * from pac where id =".$_SESSION['pac_doc'][0];
	$_SESSION['pac_doc'][1]=$_SESSION['pac_doc'][0];
	}
	}
	else {
	$sql="select * from pac where id =".$_SESSION['wyb_pac_ed_id'];
	}
	$result=mysql_query($sql);
	$row = mysql_fetch_array($result);
	#print_r($row);
?>




  <script>
  $(document).ready(function(){
	  jQuery.validator.addMethod("pac_pesel", function(value, element) {
		  var pesel = value.replace(/[\ \-]/gi, '');   
		  var rePesel = /(\d{11})/;
		  if(pesel == 0)return true;
		  if (rePesel.test(pesel)) pesel = RegExp.$1;
		  else return false;
		  pesel = pesel.split("");
		  //if(plec)
		  //{
		  // if(pesel[9]%2 && plec.search("K")!=-1) return false;
		  // else if (!pesel[9]%2 && plec.search("M")) return false;
		  //}
		  var wagi = new Array(1,3,7,9,1,3,7,9,1,3);
		  var suma=0;
		  for(i=0;i<=9;i++) suma += pesel[i]*wagi[i];
		  suma %= 10;
		  var sumaKontrolna = (10-suma) % 10;
		  if (pesel[10]==sumaKontrolna) return true;
		  else return false;
		  }, "Proszę o podanie prawidłowego numeru PESEL");
  
    $("#fancy").validate({
    	rules: {
		pac_pesel: {
			required: false,
			pac_pesel: true 
	    }
    }
        });

	
    $("#pac_pesel").keyup(function () {
        var text = $(this).val();

       if(text.length > 5){
        	
                var rok = parseInt(text.substring(0,2)); 
        	var mies = text.substring(2,4);
        	var dzien = text.substring(4,6); 
        	 
                
        	if(mies <= 20){
				rok = 1900 + rok;
        	}
                else{
				rok = 2000 + rok;
				mies = mies - 20;
                                mies = '0' + mies;
        	}
        	
              
        }



        
    	$('#pac_dataur').val(rok.toString()+"-"+mies+"-"+dzien);
      });

    
    $('.required').bestupper();
    $('.up').bestupper();
    <?php if ($row['platnik']==0) { 
     echo '$("#pac_polisa").attr("disabled", "disabled");';
     echo '$("#pac_zlecenie").attr("disabled", "disabled");';
     
     
     
    }
    ?>
    $("#platnik").change(function(){
    	 var parentCat = $("#platnik").val(), txt = "";

         if (parentCat !== "0") {

             // Enable #secondary if valid #primary is selected
        	 $("#pac_polisa").removeAttr("disabled");
             
             
             $("#polisa").toggle('slow');
            
             
         }
         else {

             // Disables #secondary if no valid #primary is selected
        	 $("#pac_polisa").attr("disabled", "disabled");
            
             $("#polisa").toggle('slow');
            
             

         }
    });
	
     
  });
     

  </script>

<?php 

$sql1="select * from sl_firmy";
$result1=mysql_query($sql1);
while($row1 = mysql_fetch_array($result1))
{
$sl_f[$row1[0]]=$row1[1];
}
$sl_f[0]='Pełnopłatny';

?>

<? if ($_SESSION['config']<>'admin') { echo '
<form action="index.php" method="POST"><input type=submit value=Anuluj name="pacjenci" class="butt4"></form>';
}
?>
<form class="fancy" id="fancy" method="post" action="">
 <fieldset >
   <legend>
	
	<? if ($_SESSION['config']=='admin') {
		echo 'Łączenie Pacjentów';
}
else echo 'Edycja Pacjenta';
?>
	
   </legend>
   <ul>
   <li>
     <label for="cnaz">Nazwisko*</label>
     <input id="cnaz" name="pac_naz" size="45" class="required" value="<?php echo $row['pac_nazwisko']; ?>" />
   </li>
   <li>
     <label for="cimie">Imię*</label>
     <input id="cimie" name="pac_imie" size="45"  class="required" value="<?php echo $row['pac_imie']; ?>" />
   </li>
   
   <li>
     <label for="cpesel">Pesel</label>
     <input name="pac_pesel" id="pac_pesel" size="14" maxlength="11" value="<?php echo $row['pac_pesel']; ?>" />
   </li>
   <li>
     <label for="cdatau">Data ur.</label>
     <input name="pac_dataur" id="pac_dataur" size="14" maxlength="11" value="<?php echo $row['pac_dataur']; ?>"/>
   </li>
   <li>
     <label for="cplatnik">Płatnik</label>
     <select name="platnik" id="platnik" size="1">
	<?php 
	ksort($sl_f);
	foreach ($sl_f as $a=>$b){
	echo '<option value="'.$a.'"';
	if ($row['platnik']==$a) echo ' selected ';
	echo '>'.$b.'</option>';	
	}
	?>	
	</select>
   </li>
   <li id="polisa" style="display: <?php if ($row['platnik']==0) echo ' none '; else echo ' list-item ' ?>">
     <label for="cpolisa">Nr polisy</label>
     <input id="pac_polisa" name="pac_polisa" size="25" value="<?php echo $row['polisa']; ?>" />
   </li>
   
<!--  <li id="zlecenie" style="display: <?php if ($row['platnik']==0) echo ' none '; else echo ' list-item ' ?>">
     <label for="czlecenie">Nr zlecenia</label>
     <input id="pac_zlecenie" name="pac_zlecenie" size="25" value="<?php echo $row['zlecenie']; ?>"/>
   </li>-->
   
   <li>
     <label for="cmiasto">Miasto</label>
     <input id="cmiasto" name="pac_miasto" size="45"  class="up" value="<?php echo $row['pac_adrm']; ?>" />
   </li>
   <li>
     <label for="ckod">Kod pocztowy</label>
     <input id="ckod" name="pac_kod" size="6" value="<?php echo $row['pac_adrk']; ?>"  />
   </li>
   
   <li>
     <label for="culica">Ulica</label>
     <input id="culica" name="pac_ulica" size="50"  class="up" value="<?php echo $row['pac_adru']; ?>"  />
   </li>
   
   <li>
     <label for="cnrdom">Nr domu</label>
     <input id="cnrdom" name="pac_nrdom" size="15" value="<?php echo $row['pac_adrd']; ?>"  />
   </li>
   
   <li>
     <label for="cnrlok">Nr lokalu</label>
     <input id="cnrlok" name="pac_nrlok" size="6" value="<?php echo $row['pac_adrl']; ?>"  />
   </li>
   
   <li>
     <label for="ctel">Nr tel</label>
     <input id="ctel" name="pac_tel" size="24" value="<?php echo $row['pac_telefon']; ?>"  />
   </li>
   
   <li>
     <label for="ctel2">Nr tel 2</label>
     <input id="ctel2" name="pac_tel2" size="24" value="<?php echo $row['pac_telefon2']; ?>"  />
   </li>
   
   <li>
     <label for="ctel3">Nr tel 3</label>
     <input id="ctel3" name="pac_tel3" size="24" value="<?php echo $row['pac_telefon3']; ?>"  />
   </li>
   
   <li>
     <label for="cosoba_kont">Osoba kontaktowa</label>
     <input id="cosoba_kont" name="osoba_kont" size="50"  class="up" value="<?php echo $row['osoba_kont']; ?>" />
   </li>
   
   <li>
     <label for="cosoba_kont_tel">Osoba kontaktowa tel.</label>
     <input id="cosoba_kont_tel" name="osoba_kont_tel" size="50" value="<?php echo $row['osoba_kont_tel']; ?>"  />
   </li>
   
	<li>
     <label for="cemial">E-mail</label>
     <input id="cemial" name="email" size="45" class="email" value="<?php echo $row['email']; ?>"  />
   </li>
   <li>
     <label for="cemial">Stymulator</label>
     <input id="cstymulator" name="stymulator" size="25" class="stymulator" value="<?php echo $row['stymulator']; ?>"  />
   </li>
   <li>
     <label for="cemial">Oświadczenie</label>
     <?php
     $osw = explode("|", $row['oswiadczenie'])
     ?>
     <input id="cemial" name="oswiadczenie[1]" class="oswiadczenie" type="checkbox" <?php if ($osw[0]=='on') echo 'checked'; ?> />
      <input name="oswiadczenie[2]" id="cemial" size="14" maxlength="11" value="<?php echo $osw[1]; ?>"/>
      <input id="cemial" name="oswiadczenie[3]" size="1" class="oswiadczenie[3]" maxlength="1" value="<?php echo $osw[2]; ?>"/>
   </li>
	<input type="hidden" name="pac_id" value="<?php echo $row['id']; ?>"> 
   
   <li>
     <? if ($_SESSION['config']<>'admin') { echo ' 
	 <input class="submit" name="form_ed_pac" type="submit" value="Zapisz"/>';
	 }
	 ?>
   </li>
   </ul>
 </fieldset>
 </form>

